package middleware

import (
	"Graphite/model"
	"Graphite/util"
	"fmt"
	"github.com/gin-gonic/gin"
)

//func MiddleWare() gin.HandlerFunc {
//	return func(c *gin.Context) {
//		t := time.Now()
//		fmt.Println("中间件开始执行了")
//		// 设置变量到Context的key中，可以通过Get()取
//		c.Set("request", "中间件")
//		status := c.Writer.Status()
//		fmt.Println("中间件执行完毕", status)
//		t2 := time.Since(t)
//		fmt.Println("time:", t2)
//	}
//}
//
//func Sleeping() gin.HandlerFunc {
//	return func(c *gin.Context) {
//		start := time.Now()
//		fmt.Println("中间件开始执行了")
//		c.Next()
//		stop := time.Since(start)
//		fmt.Println("time:", stop)
//	}
//}
//
//func AuthMiddleWare() gin.HandlerFunc {
//	return func(c *gin.Context) {
//		// 获取客户端cookie并校验
//		if cookie, err := c.Cookie("gin_cookie"); err == nil {
//			if cookie == "test" {
//				c.Next()
//				return
//			}
//		}
//		// 返回错误
//		c.JSON(http.StatusUnauthorized, gin.H{"error": "err"})
//		// 若验证不通过，不再调用后续的函数处理
//		c.Abort()
//		return
//	}
//}

//func detail (c *gin.Context)  {
//		// 取值
//		req, _ := c.Get("request")
//		fmt.Println("request:", req)
//		// 页面接收
//		c.JSON(200, gin.H{"request": req})
//}
//工序长度
func ProcessJudge() func(c *gin.Context) {
	return func(c *gin.Context) {
		url := c.Request.URL.Path
		fmt.Println(url)
		var one model.Amount
		if err:= c.ShouldBind(&one);err != nil{
			util.Return(c,200,util.PARA_ERROR,err)
			return
		}
		c.Set("one",one)
		fmt.Println(one)
		switch one.Diameter {
		case "Φ600":
			switch one.Process_Length {
			case "RP-1950":
				c.Next()
				break
			case "RP-2250":
				c.Next()
				break
			case "IP-1950":
				c.Next()
				break
			case "IP-2250":
				c.Next()
				break
			default:
				util.Return(c,200,util.PARA_ERROR,"匹配失败")
				c.Abort()
				break
			}
		case "Φ550":
			switch one.Process_Length {
			case "UHP-2250":
				c.Next()
				break
			default:
				util.Return(c,200,util.PARA_ERROR,"匹配失败")
				c.Abort()
				break
			}
		case "Φ500":
			switch one.Process_Length {
			case "RP-1950":
				c.Next()
				break
			case "RP-2250":
				c.Next()
				break
			case "IP-1950":
				c.Next()
				break
			case "IP-2250":
				c.Next()
				break
			case "HP-1950":
				c.Next()
				break
			case "UHP-1950":
				c.Next()
				break
			case "UHP-2250":
				c.Next()
				break
			default:
				util.Return(c,200,util.PARA_ERROR,"匹配失败")
				c.Abort()
				break
			}
		case "Φ450":
			switch one.Process_Length {
			case "RP-2250":
				c.Next()
				break
			case "IP-2":
				c.Next()
				break
			case "HP-2100-1":
				c.Next()
				break
			case "HP-2100-2":
				c.Next()
				break
			case "HP-2250":
				c.Next()
				break
			case "UHP-2150":
				c.Next()
				break
			case "UHP-2600":
				c.Next()
				break
			default:
				util.Return(c,200,util.PARA_ERROR,"匹配失败")
				c.Abort()
				break
			}
		case "Φ400":
			switch one.Process_Length {
			case "RP-2000":
				c.Next()
				break
			case "IP-2000":
				c.Next()
				break
			case "HP-2000":
				c.Next()
				break
			case "HP-2":
				c.Next()
				break
			case "HP-2200":
				c.Next()
				break
			case "UHP-2200":
				c.Next()
				break
			default:
				util.Return(c,200,util.PARA_ERROR,"匹配失败")
				c.Abort()
				break
			}
		case "Φ350":
			switch one.Process_Length {
			case "RP":
				c.Next()
				break
			case "IP-2":
				c.Next()
				break
			case "HP-2":
				c.Next()
				break
			default:
				util.Return(c,200,util.PARA_ERROR,"匹配失败")
				c.Abort()
				break
			}
		case "Φ300":
			switch one.Process_Length {
			case "RP":
				c.Next()
				break
			case "IP-2":
				c.Next()
				break
			default:
				util.Return(c,200,util.PARA_ERROR,"匹配失败")
				c.Abort()
				break
			}
		case "Φ250":
			switch one.Process_Length {
			case "RP-1700":
				c.Next()
				break
			case "RP-1900":
				c.Next()
				break
			case "IP-2-1700":
				c.Next()
				break
			case "IP-2-1900":
				c.Next()
				break
			default:
				util.Return(c,200,util.PARA_ERROR,"匹配失败")
				c.Abort()
				break
			}
		case "Φ200":
			switch one.Process_Length {
			case "RP":
				c.Next()
				break
			default:
				util.Return(c,200,util.PARA_ERROR,"匹配失败")
				c.Abort()
				break
			}
		case "Φ234":
			switch one.Process_Length {
			case "IP(白点)":
				c.Next()
				break
			case "IP(黄点)":
				c.Next()
				break
			case "IP(红点)":
				c.Next()
				break
			default:
				util.Return(c,200,util.PARA_ERROR,"匹配失败")
				c.Abort()
				break
			}
		case "Φ256":
			switch one.Process_Length {
			case "IP(白点)":
				c.Next()
				break
			case "IP(黄点)":
				c.Next()
				break
			case "IP(红点)":
				c.Next()
				break
			default:
				util.Return(c,200,util.PARA_ERROR,"匹配失败")
				c.Abort()
				break
			}
		case "Φ288":
			switch one.Process_Length {
			case "IP(白点)":
				c.Next()
				break
			case "IP(黄点)":
				c.Next()
				break
			case "IP(红点)":
				c.Next()
				break
			default:
				util.Return(c,200,util.PARA_ERROR,"匹配失败")
				c.Abort()
				break
			}
		case "Φ315":
			switch one.Process_Length {
			case "IP(白点)":
				c.Next()
				break
			case "IP(黄点)":
				c.Next()
				break
			case "IP(红点)":
				c.Next()
				break
			default:
				util.Return(c,200,util.PARA_ERROR,"匹配失败")
				c.Abort()
				break
			}
		case "Φ333":
			switch one.Process_Length {
			case "IP(白点)":
				c.Next()
				break
			case "IP(黄点)":
				c.Next()
				break
			case "IP(红点)":
				c.Next()
				break
			default:
				util.Return(c,200,util.PARA_ERROR,"匹配失败")
				c.Abort()
				break
			}
		case "次品":
			switch one.Process_Length {
			case "Φ600":
				c.Next()
				break
			case "Φ550":
				c.Next()
				break
			case "Φ500":
				c.Next()
				break
			case "Φ450":
				c.Next()
				break
			case "Φ400":
				c.Next()
				break
			case "Φ350":
				c.Next()
				break
			case "Φ300":
				c.Next()
				break
			case "Φ250":
				c.Next()
				break
			case "Φ200":
				c.Next()
				break
			case "Φ234":
				c.Next()
				break
			case "Φ256":
				c.Next()
				break
			case "Φ288":
				c.Next()
				break
			case "Φ315":
				c.Next()
				break
			case "Φ333":
				c.Next()
				break
			default:
				util.Return(c,200,util.PARA_ERROR,"匹配失败")
				c.Abort()
				break
			}
		default:
			util.Return(c,200,util.PARA_ERROR,"匹配失败")
			c.Abort()
			break
			}
		}
	}

